package com.wiseMen.weixin.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

import com.alibaba.fastjson.JSONObject;

public class RequestDataUtils {

	public static JSONObject post(String param) throws IOException{
		System.out.println(param);
		String url = Constant.url;
		param = URLEncoder.encode(param, "UTF-8");
		url = url.replace("{param}", param);
		System.out.println(url);
		BufferedReader in = null;
		StringBuilder sb = new StringBuilder();
		URL urlObject = new URL(url);
		URLConnection uc = urlObject.openConnection();
		in = new BufferedReader(new InputStreamReader(uc.getInputStream(),"UTF-8"));
		String inputLine = null;
		while ((inputLine = in.readLine()) != null) {
			sb.append(inputLine);
		}
		JSONObject json = null;
		try{
			json = JSONObject.parseObject(sb.toString());
		}catch(Exception ex){
			json = new JSONObject();
			json.put("state", "error");
			json.put("message", "返回数据非Json格式");
		}
		return json;
	}
}
